package com.example.demo.security.sysLogin.service;


import com.example.demo.security.sysUser.dao.UserDao;
import com.example.demo.security.sysUser.entity.UserBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class LoginService{

    @Autowired
    private UserDao userDao;

    public UserBean queryByName(String name){
        return userDao.queryByName(name);
    }

    /**
     * 注册用户
     * @author 自嘲
     * @param userBean
     * @return
     */
    public Integer registerUser(UserBean userBean){
        if (userBean.getLoginName()!=null){
            UserBean userBean1=userDao.queryByName(userBean.getLoginName());
            if (userBean1==null){
                userBean.setHeadPortrait("无");
                userBean.setEndTime(new Date());
                userBean.setState(1);
                return userDao.registerUser(userBean);
            }else {
                return -1;
            }
        }else {
            return 0;
        }
    }


    public Integer updateUserStateOnLine(Integer id){
        return userDao.updateUserStateOnLine(id);
    }

    /**
     * 修改用户在线状态
     * @author 自嘲
     * @param id
     * @return
     */
    public Integer updateUserState(Integer id){
        return userDao.updateUserState(id);
    }
}
